package com.lmt.ymcc.web.controller;

import com.lmt.ymcc.dto.CourseDoc;
import com.lmt.ymcc.dto.CourseEsSearchDto;
import com.lmt.ymcc.result.JSONResult;
import com.lmt.ymcc.result.PageList;
import com.lmt.ymcc.service.ICourseEsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: TODO
 * @Author: Amazing
 * @Date: 2022/8/14 15:36
 * @Version: 1.0
 */
@RestController
@RequestMapping("/course")
public class CourseEsController {
    @Autowired
    private ICourseEsService courseEsService;

    /**
     * 保存课程到Es
     * @param doc
     * @return
     */
    @PostMapping("/save")
    @PreAuthorize("hasAuthority('es:saveCourse')")
    public JSONResult saveCourse(@RequestBody CourseDoc doc){
        courseEsService.saveCourse(doc);
        return JSONResult.success();
    }

    @PostMapping("/delete")
    public JSONResult delete(@RequestBody Long id){
        courseEsService.delete(id);
        return JSONResult.success();
    }
    @PostMapping("/search")
    public JSONResult search(@RequestBody CourseEsSearchDto dto){
        PageList<CourseDoc> pageList = courseEsService.search(dto);
        return JSONResult.success(pageList);
    }
}
